package kr.hkit.androidcomplete01;

import kr.hkit.androidcomplete01.ch04.Ch04Main;
import kr.hkit.androidcomplete01.ch05.Ch05Main;
import kr.hkit.androidcomplete01.ch06.Ch06Main;
import kr.hkit.androidcomplete01.ch07.Ch07Main;
import kr.hkit.androidcomplete01.ch08.Ch08Main;
import kr.hkit.androidcomplete01.ch09.Ch09Main;
import kr.hkit.androidcomplete01.ch10.Ch10Main;
import kr.hkit.androidcomplete01.ch11.Ch11Main;
import kr.hkit.androidcomplete01.ch12.Ch12Main;
import kr.hkit.androidcomplete01.ch13.Ch13Main;
import kr.hkit.androidcomplete01.ch14.Ch14Main;
import kr.hkit.androidcomplete01.ch15.Ch15Main;
import kr.hkit.androidcomplete01.ch16.Ch16Main;
import kr.hkit.androidcomplete01.ch17.Ch17Main;
import kr.hkit.androidcomplete01.ch18.Ch18Main;
import kr.hkit.androidcomplete01.ch19.Ch19Main;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {

	private String[] lists;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/*setContentView(R.layout.activity_main);
		//activity_main 참조해서 전개. 
		//실행전에 이미 생성되어있으므로 그냥 참조해서 전개
		 */
		
		lists = getResources().getStringArray(R.array.main_list); //참조해서 가져와라
		
		/*for (String str : lists) {
			Log.d("lists", str); //배열안의 내용 보임. 확인용
		}*/
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lists);
		setListAdapter(adapter); //배열안의 목록 보여주는 것 
	}
	
	@Override //리스트에서 아이템을 선택했을 때 자동으로 호출됨 
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		//String text = "View v" + v.toString() + " : position = " + position + ", id= " + id;
		//Toast.makeText(this, text, Toast.LENGTH_LONG).show();
		
		Intent intent = null; //intent에 수행될 정보를 담아서 실행해야함
		switch(position){
		case 0: 
			intent = new Intent(this, Ch04Main.class); //이거를 실행시켜달라
			break;
		case 1:
			//Toast.makeText(this, "즐거운 안드로이드", Toast.LENGTH_LONG).show();
			intent = new Intent(this, Ch05Main.class);
			break;
		case 2:
			intent = new Intent(this, Ch06Main.class);
			break;
		case 3:
			intent = new Intent(this, Ch07Main.class);
			break;
		case 4:
			intent = new Intent(this, Ch08Main.class);
			break;
		case 5:
			intent = new Intent(this, Ch09Main.class);
			break;
		case 6:
			intent = new Intent(this, Ch10Main.class);
			break;
		case 7:
			intent = new Intent(this, Ch11Main.class);
			break;
		case 8:
			intent = new Intent(this, Ch12Main.class);
			break;
		case 9:
			intent = new Intent(this, Ch13Main.class);
			break;
		case 10:
			intent = new Intent(this, Ch14Main.class);
			break;
		case 11:
			intent = new Intent(this, Ch15Main.class);
			break;
		case 12:
			intent = new Intent(this, Ch16Main.class);
			break;
		case 13:
			intent = new Intent(this, Ch17Main.class);
			break;
		case 14:
			intent = new Intent(this, Ch18Main.class);
			break;
		case 15:
			intent = new Intent(this, Ch19Main.class);
			break;
		}
		
		startActivity(intent);
		
	}
}
